package PackageIO;

import java.io.*;

public class Test03 {
    public Test03(){
/*
        3.写程序判断D盘根目录下a.txt文件是否存在，如果存在则向其内依次写入字符串 “wil1 Smith”，整数25，写入后再从文件中将其读出。
    （利用RandomAccessFile类或DatalutputStream, DataInputStream)
*/
//        File file = new File("SchoolTest/src/PackageIO/test04.txt");
        File  file = new File("D:\\a.txt");
        if (file.exists()){
            try {
                DataOutputStream dos = new DataOutputStream(new FileOutputStream(file));
                DataInputStream dis = new DataInputStream(new FileInputStream(file));
                dos.writeUTF("will Smith");
                dos.writeInt(25);
                System.out.println(dis.readUTF());
                System.out.println(dis.readInt());
                dis.close();
                dos.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }else {
            System.out.println("没有这个文件");
        }
    }
    public static void main(String[] args) {
        new Test03();
    }
}
